package ua.kharkov.knure.pereverziev.diploma.db.DAOServices;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ua.kharkov.knure.pereverziev.diploma.db.entity.User;

public class UserService extends CommonService<User> {

	private final Logger log = LoggerFactory.getLogger(UserService.class);

	public UserService() {
		super(User.class);
	}

	public User logIn(final String email, final String password) {
		final User user = new User();
		user.setEmail(email);
		final List<User> users = getList(user);
		if (users != null && users.size() == 1
				&& users.get(0).getPassword().equals(password))
			return users.get(0);
		else {
			log.debug("List of found users: " + users);
			return null;
		}
	}

	public boolean checkPresence(final String email) {
		final User user = new User();
		user.setEmail(email);
		final List<User> users = getList(user);
		if (users != null && users.size() == 1)
			return true;
		else
			return false;
	}

	public User getByEmail(final String email) {
		final User user = new User();
		user.setEmail(email);
		final List<User> users = getList(user);
		if (users != null && users.size() == 1)
			return users.get(0);
		else
			return null;
	}

}
